package com.HuiShou.controller.common;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.HuiShou.common.annotation.Log;
import com.HuiShou.common.core.controller.BaseController;
import com.HuiShou.common.core.domain.AjaxResult;
import com.HuiShou.common.enums.BusinessType;
import com.HuiShou.domain.RecycleCategory;
import com.HuiShou.service.IRecycleCategoryService;
import com.HuiShou.common.utils.poi.ExcelUtil;
import com.HuiShou.common.core.page.TableDataInfo;

/**
 * 可回收物分类Controller
 *
 * @author lyz
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/recycle/category")
public class RecycleCategoryController extends BaseController
{
    @Autowired
    private IRecycleCategoryService recycleCategoryService;

    /**
     * 查询可回收物分类列表
     */
    @PreAuthorize("@ss.hasPermi('recycle:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecycleCategory recycleCategory)
    {
        startPage();
        List<RecycleCategory> list = recycleCategoryService.selectRecycleCategoryList(recycleCategory);
        return getDataTable(list);
    }

    /**
     * 导出可回收物分类列表
     */
    @PreAuthorize("@ss.hasPermi('recycle:category:export')")
    @Log(title = "可回收物分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecycleCategory recycleCategory)
    {
        List<RecycleCategory> list = recycleCategoryService.selectRecycleCategoryList(recycleCategory);
        ExcelUtil<RecycleCategory> util = new ExcelUtil<RecycleCategory>(RecycleCategory.class);
        util.exportExcel(response, list, "可回收物分类数据");
    }

    /**
     * 获取可回收物分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('recycle:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") String categoryId)
    {
        return success(recycleCategoryService.selectRecycleCategoryByCategoryId(categoryId));
    }

    /**
     * 新增可回收物分类
     */
    @PreAuthorize("@ss.hasPermi('recycle:category:add')")
    @Log(title = "可回收物分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecycleCategory recycleCategory)
    {
        return toAjax(recycleCategoryService.insertRecycleCategory(recycleCategory));
    }

    /**
     * 修改可回收物分类
     */
    @PreAuthorize("@ss.hasPermi('recycle:category:edit')")
    @Log(title = "可回收物分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecycleCategory recycleCategory)
    {
        return toAjax(recycleCategoryService.updateRecycleCategory(recycleCategory));
    }

    /**
     * 删除可回收物分类
     */
    @PreAuthorize("@ss.hasPermi('recycle:category:remove')")
    @Log(title = "可回收物分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable String[] categoryIds)
    {
        return toAjax(recycleCategoryService.deleteRecycleCategoryByCategoryIds(categoryIds));
    }
}
